package com.manage.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.manage.mapper.StoreOrdersListMapper;
import com.manage.pojo.operation.StoreOrdersList;
import com.manage.utils.PagedResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class StoreOrdersListServiceImpl implements StoreOrdersListService{

    @Autowired
    private StoreOrdersListMapper storeOrdersListMapper;

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public PagedResult queryStoreOrdersInfoByUserId(Integer page, Integer pageSize, String userId) {
        PageHelper.startPage(page, pageSize);
        List<StoreOrdersList> list = storeOrdersListMapper.queryStoreOrdersList(userId);
        PageInfo<StoreOrdersList> pageList = new PageInfo<>(list);
        PagedResult pagedResult = new PagedResult();
        pagedResult.setPage(page);
        pagedResult.setTotal(pageList.getPages());
        pagedResult.setRows(list);
        pagedResult.setRecords(pageList.getTotal());
        return pagedResult;
    }
}
